
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
 */
package supermarketgui;

//~--- JDK imports ------------------------------------------------------------

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;

import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author JK
 */
@Entity
@Table(name = "PRODUCT")
@XmlRootElement
@NamedQueries( {
    @NamedQuery(
        name  = "Product.findAll",
        query = "SELECT p FROM Product p"
    ) , @NamedQuery(
        name  = "Product.findByProductId",
        query = "SELECT p FROM Product p WHERE p.productId = :productId"
    ) , @NamedQuery(
        name  = "Product.findByName",
        query = "SELECT p FROM Product p WHERE p.name = :name"
    ) , @NamedQuery(
        name  = "Product.findByCode",
        query = "SELECT p FROM Product p WHERE p.code = :code"
    ) , @NamedQuery(
        name  = "Product.findByPoints",
        query = "SELECT p FROM Product p WHERE p.points = :points"
    ) , @NamedQuery(
        name  = "Product.findByPrice",
        query = "SELECT p FROM Product p WHERE p.price = :price"
    )
})
public class Product implements Serializable {
    private static final long     serialVersionUID = 1L;
    @Transient
    private final PropertyChangeSupport changeSupport    = new PropertyChangeSupport(this);
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "PRODUCT_ID")
    private Integer               productId;
    @Basic(optional = false)
    @Column(name = "NAME")
    private String                name;
    @Basic(optional = false)
    @Column(name = "CODE")
    private String                code;
    @Basic(optional = false)
    @Column(name = "POINTS")
    private int                   points;
    @Basic(optional = false)
    @Column(name = "PRICE")
    private float                 price;

    public Product() {}

    public Product(Integer productId) {
        this.productId = productId;
    }

    public Product(Integer productId, String name, String code, int points, float price) {
        this.productId = productId;
        this.name      = name;
        this.code      = code;
        this.points    = points;
        this.price     = price;
    }

    public Integer getProductId() {
        return productId;
    }

    public void setProductId(Integer productId) {
        Integer oldProductId = this.productId;

        this.productId = productId;
        changeSupport.firePropertyChange("productId", oldProductId, productId);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        String oldName = this.name;

        this.name = name;
        changeSupport.firePropertyChange("name", oldName, name);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        String oldCode = this.code;

        this.code = code;
        changeSupport.firePropertyChange("code", oldCode, code);
    }

    public int getPoints() {
        return points;
    }

    public void setPoints(int points) {
        int oldPoints = this.points;

        this.points = points;
        changeSupport.firePropertyChange("points", oldPoints, points);
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        float oldPrice = this.price;

        this.price = price;
        changeSupport.firePropertyChange("price", oldPrice, price);
    }

    @Override
    public int hashCode() {
        int hash = 0;

        hash += ((productId != null)
                 ? productId.hashCode()
                 : 0);

        return hash;
    }

    @Override
    public boolean equals(Object object) {

        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Product)) {
            return false;
        }

        Product other = (Product) object;

        return ((this.productId != null) || (other.productId == null)) && ((this.productId == null) || this.productId.equals(other.productId));
    }

    @Override
    public String toString() {
        return "supermarketgui.Product[ productId=" + productId + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
